<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <script>
                function title() {
                    document.getElementById('admin').className='selected';
                }
                window.onload=title;
            </script>
            <h:form id="incomeCreate" enctype="multipart/form-data">
                <h1 class="title">
                    <a href="#" class="back" onclick="history.go(-1)"/>
                    Outras Receitas
                </h1>
                <p:messages showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns">
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Cadastrar</h4></legend>
                            <p:panel id="resultPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix " >

                                <p:outputLabel for="tipo" value="Tipo:" styleClass="grid_2"/>  
                                <div class="grid_5">
                                    <p:selectOneMenu value="#{managerFinancialReceitas.income.typeCredit}" 
                                                     id="tipo" styleClass="grid_4" style="width: 100%;" >  
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems  value="#{managerFinancialReceitas.selectTypeCredit()}"/>  
                                    </p:selectOneMenu>
                                </div>
                                <div class="clear"/>

                                <p:outputLabel value="Valor:" styleClass="grid_2"/>  
                                <p:inputText id="famount" styleClass="grid_5" required="true"
                                             requiredMessage="O campo 'valor' é necessário"
                                             value="#{managerFinancialReceitas.income.totalAmount}"
                                             onkeypress="jQuery(this).autoNumeric({aSign:'R$ ',aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" locale="pt,BR"/>
                                </p:inputText>

                                <div class="clear"/>

                                <p:outputLabel value="Data:" styleClass="grid_2"/>  
                                <div class="grid_5">
                                    <p:calendar value="#{managerFinancialReceitas.income.createAt}" 
                                                showOn="button" pattern="dd/MM/yyyy"/>
                                </div>

                                <div class="clear"/>

                                <p:outputLabel value="Descrição:" styleClass="grid_2"/>  
                                <p:inputTextarea value="#{managerFinancialReceitas.income.descricao}" styleClass="grid_19" />


                                <div class="clear"/>

                                <div class="buttonAction">
                                    <p:commandButton value="Adicionar" icon="ui-icon-plus" process="@form"
                                                     update="@form, tableEntrada"
                                                     actionListener="#{managerFinancialReceitas.add()}" />
                                </div>

                                <p:dataTable id="tableEntrada" var="in" value="#{managerFinancialReceitas.incomes}" 
                                             styleClass="grid_24"
                                             rowIndexVar="rowid"
                                             rowKey="#{r.id}"
                                             rows="15" paginator="true"  
                                             paginatorPosition="bottom"
                                             emptyMessage="Nenhum registro"
                                             >  
                                    <f:facet name="header">
                                        Registros
                                    </f:facet>
                                    <p:column headerText="Tipo" width="400">  
                                        <h:outputText value="#{in.typeCredit.desc}"/>
                                    </p:column>  
                                    <p:column headerText="Data Realização" width="400">  
                                        <h:outputText value="#{in.createAt}">
                                            <f:convertDateTime pattern="dd/MM/yyyy" />
                                        </h:outputText>
                                    </p:column>  
                                    <p:column headerText="Descrição" width="400">  
                                        <h:outputText value="#{in.descricao}"/>
                                    </p:column>  
                                    <p:column headerText="Valor Total" width="400" style="text-align: right;">  
                                        <h:outputText value="#{in.totalAmount}">
                                            <f:convertNumber pattern="#0.00" />
                                        </h:outputText>
                                        <f:facet name="footer"> 
                                            <h:outputText value="#{managerFinancialReceitas.total}" 
                                                          style="float: right; font-weight:bold;">
                                            <f:convertNumber pattern="#0.00" />
                                        </h:outputText>
                                        </f:facet> 
                                    </p:column>
                                </p:dataTable>
                                
                                
                                <div class="buttonAction">
                                    <p:commandButton value="Concluir" icon="ui-icon-plus" process="@this"
                                                     update="@form"
                                                     actionListener="#{managerFinancialReceitas.salvar()}" />
                                </div>
                                
                            </p:panel>
                        </fieldset>
                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
